<%
/**
 * fourth wizard page / tab
 *
 * @author	Jeroen Wesbeek <work@osx.eu>
 * @package AjaxFlow
 */
%>
<script type="text/javascript" >
 function remappingBean(){
	    $("#add_more_debito").click(function(e){
	        e.preventDefault();
	        addDebito('','','','','','');
	    });	

	    <g:if test="${customer?.debito}">
		    <g:each in="${customer.debito}" var="item">
		    	<g:if test="${item.type.type}">
		    			addDebito('${item.type.type}','${item.credit}','${item.capitalRes}','${item.rate}','${item.partner}','${item.notes}');	
		    	 </g:if>	
			</g:each>
	    </g:if>	 	    
 }	        

 	function addDebito(tip,cre,car,rat,par,not){
	    	var next = parseInt($("#count_debito").val());
	        var addto = "#new_row_debito_" + (next);
	        var divRow=$('<div class="row" id="new_row_debito_' + (next+1)+'"></div>');
	        var divColBtn=$('<div class="col-sm-1"></div>');
	        var removeButton = $('<button type="button" class="btn btn-danger btn-md " id="remove_debito_' + (next+1) + '" >'+
	    	        				'<i class="glyphicon glyphicon-trash"></i></button>	');
	        removeButton.click(function(e){
                e.preventDefault();
                var fieldNum = this.id.charAt(this.id.length-1);
                var fieldID = "#new_row_debito_" + fieldNum;
                $(fieldID).remove();
                var next = parseInt($("#count_debito").val());
                next = (next -1);
                $("#count_debito").val(next);  
            });

	        divColBtn.append(removeButton)
	        divRow.append(divColBtn);
	        
	        var rendValue=$('<div class="col-sm-5"></div>');
	        var ft = $('<div class="form-group"></div>');
	        var selectContainer=$('<div class="input-group" ><span class="input-group-addon"><i class="fa fa-briefcase fa-lg fa-fw">'+
	    	        '</i></span></div>');  
	        var allOption=$('<select id="debitType" name="debitType" class="form-control"/>');
	        
	        <g:each in="${com.macrosolution.exdebito.DebitType?.list()}" var="a" status="i">
	        var divOption${i}=null
	        if('${a.type}' == tip){
	        	divOption${i}=$('<option value="${a.type}" selected >${a.type}</option>');
		        }else{
		        	divOption${i}=$('<option value="${a.type}" >${a.type}</option>');
			}

	        allOption.append(divOption${i});
	        </g:each>
	        selectContainer.append(allOption);
	        ft.append(selectContainer);	
			rendValue.append(ft);
	        divRow.append(rendValue);

	        var rendValue2=$('<div class="col-sm-5 col-md-offset-1"><div class="form-group"><div class="input-group">'+
	    	        		'<span class="input-group-addon"><i class="fa fa-money fa-lg fa-fw"></i></span>'+
	    	        			'<input class="form-control input-md" placeholder="Creditori" type="text" name="credit" id="credit" value="'+((cre!=null)?cre:'')+'">'+
	    	        		'</div></div></div><div class="col-sm-5 col-md-offset-1"><div class="form-group"><div class="input-group">'+
	    	        		'<span class="input-group-addon"><i class="fa fa-eur fa-lg fa-fw"></i></span>'+
	    	        			'<input class="form-control input-md currency" placeholder="Capitale Residuo" type="text" name="capitalRes" id="capitalRes" value="'+((car!=null)?car:'')+'">'+
	    	        		'</div></div></div><div class="col-sm-5 col-md-offset-1"><div class="form-group"><div class="input-group">'+
	    	        		'<span class="input-group-addon"><i class="fa fa-eur fa-lg fa-fw"></i></span>'+
			        			'<input class="form-control input-md currency" placeholder="Importo Rata" type="text" name="rate" id="rate" value="'+((rat!=null)?rat:'')+'">'+
			        		'</div></div></div><div class="col-sm-5 col-md-offset-1"><div class="form-group"><div class="input-group">'+
			        		'<span class="input-group-addon"><i class="fa fa-user fa-lg fa-fw"></i></span>'+
			        			'<input class="form-control input-md" placeholder="Cointestatario/Garante" type="text" name="partner" id="partner" value="'+((par!=null)?par:'')+'">'+
			        		'</div></div></div><div class="col-sm-5 col-md-offset-1"><div class="form-group"><div class="input-group">'+
			        		'<span class="input-group-addon"><i class="fa fa-edit fa-lg fa-fw"></i></span>'+
			        			'<input class="form-control input-md" placeholder="Stato Rapporto e Note" type="text" name="notes" id="notes" value="'+((not!=null)?not:'')+'">'+
			        		'</div></div></div></div>');
	        divRow.append(rendValue2);
	        next = next + 1;
	        $(addto).after(divRow);
	        $("#count_debito").val(next);  
	        currencyFormatter();
 	} 
 	
 	$(document).ready(function() {
 	    $('.form-control').on('change',function(){
 	        if($(this).val() == '4'){
 	            $('.p').show('slow');
 	        } else {
	            $('.p').hide();
 	 	 	}
 	    })  
 	});	


</script>
<af:page>
<div class="alert alert-danger fade in" id="validity_label"></div>
<g:if test="${interview}">
<div class="col-sm-3 col-md-offset-9">
	<h3>Intervista : <exdutility:number_interview value="${interview?.id }"/></h3>
</div>
</g:if>

<h3>Aggiungi Debito &nbsp;&nbsp;&nbsp;
	<a class="collapsed">  
		<button type="button" class="btn btn-info btn-lg " id="add_more_debito" style="margin-bottom:12px">
			<i class="fa fa-plus-circle"></i>
		</button>
		
	</a>
</h3>
<input type="hidden" name="count_debito" id="count_debito" value="0" />
<div id="new_row_debito_0"></div>

</br>

<h3>Approfondimenti su Eventuali Cessioni / Deleghe o CPI</h3>
<div class="row">
	<div class="col-sm-7 col-md-offset-1">
		<div class="smart-form inline-group">
			<h6>E' la prima cessione del quinto o delega di pagamento che stipuli?</h6>
		</div>
	</div>
	<div class="col-sm-1 col-md-offset-1">
		<div class="smart-form inline-group">
			<label class="radio">
				<input type="radio" name="cessioniDeleghe" class="checkbox_sex" id="cessioniDeleghe" value="true" 
				<g:if test="${interview?.acdCPI?.cessioniDeleghe==true}">checked</g:if>>
				<i></i>SI</label>	
		</div>
	</div>
	<div class="col-sm-1 ">
		<div class="smart-form inline-group">
			<label class="radio">
				<input type="radio" name="cessioniDeleghe" class="cessioniDeleghe" id="cessioniDeleghe" value="false" 
				<g:if test="${interview?.acdCPI?.cessioniDeleghe==false}">checked</g:if>>
				<i></i>NO</label>
		</div>
	</div>
</div>

<div class="row">
	<div class="col-sm-7 col-md-offset-1">
		<div class="smart-form inline-group">
			<h6>Sul contratto di mutuo ricordi se hai stipulato una polizza di copertura assicurativa (CPI)?</h6>
		</div>
	</div>
	<div class="col-sm-1 col-md-offset-1">
		<div class="smart-form inline-group">
			<label class="radio">
				<input type="radio" name="cPI" class="checkbox_sex" id="cPI" value="true" 
					<g:if test="${interview?.acdCPI?.cPI==true}">checked</g:if>>
				<i></i>SI</label>	
		</div>
	</div>
	<div class="col-sm-1 ">
		<div class="smart-form inline-group">
			<label class="radio">
				<input type="radio" name="cPI" class="checkbox_sex" id="cPI" value="false" 
					<g:if test="${interview?.acdCPI?.cPI==false }">checked</g:if>>
				<i></i>NO</label>
		</div>
	</div>
</div>
</br>

<h3>Informazioni Generali sull'Utente</h3>
<div class="row">
	<div class="col-sm-5 col-md-offset-1">
		<div class="form-group">
			<div class="smart-form inline-group">
			<h6>Cosa vorrebbe ottenere il cliente dalla procedura?</h6>
			</div>
		</div>
	</div>

	<div class="col-sm-5">
		<div class="form-group">
			<div class="input-group">
				<span class="input-group-addon"><i class="fa fa-info fa-lg fa-fw"></i></span>
				<g:select class="form-control" id="motiveSelect" name="motiveSelect" from="${com.macrosolution.exdebito.MotiveInterviewType?.list()}" 
					value="${interview?.motiveInterview?.motiveInterviewType?.id}" optionKey="id" optionValue="motiveInterviewType" noSelection="['no':'- Seleziona la risposta -']"/>
			</div>
		</div>
	</div>
</div>
<g:if test="${interview?.motiveInterview?.altroSpec && interview?.motiveInterview?.motiveInterviewType?.id==4}">
<div class="p">
</g:if><g:else>
<div class="p" style="display:none">
</g:else>
	<div class="row">
		<div class="col-sm-5 col-md-offset-1">
			<div class="form-group">
				<div class="input-group">
				</div>
			</div>
		</div>
		<div class="col-sm-5">
			<div class="form-group">
				<div class="input-group">
					<span class="input-group-addon"><i class="fa fa-edit fa-lg fa-fw"></i></span>
					<g:textArea class="form-control input-md" placeholder="Specificare la Risposta 'Altro'" 
						name="altroSpec" id="altroSpec" value="${interview?.motiveInterview?.altroSpec}" />
					
				</div>
			</div>
		</div>
	</div>
</div>
<h3>Note di Carattere Generale</h3>
<div class="row">
	<div class="col-sm-5 col-md-offset-1">
		<div class="form-group">
			<div class="input-group">
				<span class="input-group-addon"><i class="fa fa-edit fa-lg fa-fw"></i></span>
				<g:textArea class="form-control input-md" placeholder="Note" 
					name="note" id="note" value="${interview?.note}" />
				
			</div>
		</div>
	</div>
</div>

</br></br>
<div style="border-top: 2px solid #006DBA; padding-top: 2px;"></div>
</af:page>
